home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-19 | 2.3 KB | 93 lines | [TEXT/ALFA] |
- #================================================================================
- # 'greplist' and 'grepfset' are used for batch searching from the "find" dialog.
- # Hence, you really shouldn't mess with them unless you know what you are doing.
- #================================================================================
- proc greplist {args} {
- set num [expr [llength $args] - 2]
- set exp [lindex $args $num]
- set arglist [lindex $args [expr $num + 1]]
-
- set opened 0
- set owin 0
- set cid [scancontext create]
-
- set cmd [lrange $args 0 [expr $num - 1]]
- eval scanmatch $cmd {$cid $exp {
- if (!$owin) {
- set owin 1
- new -n {* Batch Find *}
-
- global winModes
- set name [lindex [winNames] 0]
- changeMode [set winModes($name) Brws]
-
- insertText "(<cr> to go to match)\r-----\r"
- set w [lindex [winNames -f] 0]
- set opened 1
- }
- set l [expr 20 - [string length [file tail $f]]]
- insertText -w $w "\"[file tail $f]\"[format "%$l\s" ""]; Line $matchInfo(linenum): $matchInfo(line)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$f\r"}
- }
-
- foreach f $arglist {
- message [file tail $f]
- if {![catch {set fid [open $f]}]} {
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
-
- if {$opened} {
- select [nextLineStart [nextLineStart 0]] [nextLineStart [nextLineStart [nextLineStart 0]]]
- setWinInfo dirty 0
- setWinInfo read-only 1
- }
- message ""
- }
-
- proc grepfset {args} {
- global fileSets
-
- set num [expr [llength $args] - 2]
- set exp [lindex $args $num]
- set fset [lindex $args [expr $num + 1]]
- eval greplist [lrange $args 0 [expr $num-1]] {$exp $fileSets($fset)}
- }
-
- proc grep {exp args} {
- set files {}
- foreach arg $args {
- if {![catch {glob -t TEXT $arg} lst]} {
- append files " " $lst
- }
- if {![catch {glob -t ttro $arg} lst]} {
- append files " " $lst
- }
- }
- if {$files==""} {return $lst}
- set cid [scancontext create]
- scanmatch $cid $exp {
- if {!$blah} {
- set blah 1
- set lines "(<cr> to go to match)\r"
- }
- set l [expr 20 - [string length [file tail $f]]]
- append lines "\"[file tail $f]\"[format "%$l\s" ""]; Line $matchInfo(linenum): $matchInfo(line)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$f\r"
- }
-
- set blah 0
- set lines ""
-
- foreach f $files {
- if {![catch {set fid [open $f]}]} {
- message [file tail $f]
- scanfile $cid $fid
- close $fid
- }
- }
- scancontext delete $cid
- return [string trimright $lines "\r"]
- }
-
-